//
//  TCLYWalletViewController.m
//  YuErmuYing
//
//  Created by LYang on 16/8/22.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "TCLYWalletViewController.h"
#import "TCLYBillViewController.h"
#import "TCLYTopUpViewController.h"
#import "TCLYWithdrawalViewController.h"
#import "Macros.h"
#import "Masonry.h"

@interface TCLYWalletViewController ()

@end

@implementation TCLYWalletViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self createTitleView];
    [self createView];
}
-(void)createView{
    UIButton * imageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [imageBtn setImage:[UIImage imageNamed:@"LYMoney"] forState:UIControlStateNormal];
    [self.view addSubview:imageBtn];
    [imageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(45/667.0*screenHeight);
        make.centerX.mas_equalTo(self.view);
        make.height.mas_equalTo(80/375.0*screenWidth);
        make.width.mas_equalTo(80/375.0*screenWidth);
    }];
    
    UILabel * myBalancelabel = [[UILabel alloc] init];
    myBalancelabel.text = @"我的余额";
    myBalancelabel.textColor = blackFont;
    myBalancelabel.textAlignment = NSTextAlignmentCenter;
    myBalancelabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:myBalancelabel];
    [myBalancelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(imageBtn.mas_bottom).offset(25/667.0*screenHeight);
        make.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(100/375.0*screenWidth);
        make.height.mas_equalTo(20);
    }];
    
    UILabel * moneyLabel = [[UILabel alloc] init];
    moneyLabel.textColor = blackFont;
    moneyLabel.textAlignment = NSTextAlignmentCenter;
    moneyLabel.text = [NSString stringWithFormat:@"¥ %@",self.moneyStr];
    moneyLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(myBalancelabel.mas_bottom).offset(15/667.0*screenHeight);
        make.centerX.mas_equalTo(self.view);
        make.width.mas_equalTo(200/375.0*screenWidth);
        make.height.mas_equalTo(20);
    }];
    
    UIButton * topUpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    topUpBtn.backgroundColor = btnColor;
    [topUpBtn setTitle:@"充值" forState:UIControlStateNormal];
    [topUpBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    topUpBtn.layer.cornerRadius = 5;
    topUpBtn.layer.masksToBounds = YES;
    topUpBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [topUpBtn addTarget:self action:@selector(topUpBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:topUpBtn];
    [topUpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(moneyLabel.mas_bottom).offset(100/667.0*screenHeight);
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(46);
    }];
    
    UIButton * withdrawalBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    withdrawalBtn.backgroundColor = [UIColor whiteColor];
    [withdrawalBtn setTitle:@"提现" forState:UIControlStateNormal];
    [withdrawalBtn setTitleColor:btnColor forState:UIControlStateNormal];
    [withdrawalBtn addTarget:self action:@selector(withdrawalBtnAction) forControlEvents:UIControlEventTouchUpInside];
    withdrawalBtn.layer.cornerRadius = 5;
    withdrawalBtn.layer.masksToBounds = YES;
    withdrawalBtn.layer.borderColor = btnColor.CGColor;
    withdrawalBtn.layer.borderWidth = 1;
    withdrawalBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:withdrawalBtn];
    [withdrawalBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(topUpBtn.mas_bottom).offset(10);
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(46);
    }];
    
}
-(void)createTitleView{
    self.navigationController.navigationBar.barStyle = UIBarMetricsCompactPrompt;
    self.navigationController.navigationBar.backgroundColor = statusColor;
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, -20, screenWidth, 20)];
    view.backgroundColor = navColor;
    [self.navigationController.navigationBar addSubview:view];
    
    UILabel * titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"钱包";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.frame = CGRectMake(0, 0, 50, 20);
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    self.navigationItem.titleView = titleLabel;
    
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(12, 22, 20, 20);
    [leftBtn setImage:[UIImage imageNamed:@"left"] forState:UIControlStateNormal];
    leftBtn.tag = 91;
    [leftBtn addTarget:self action:@selector(statusBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    rightBtn.tag = 92;
    [rightBtn setTitle:@"明细" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    rightBtn.frame = CGRectMake(screenWidth-12-20, 22, 24, 24);
    [rightBtn addTarget:self action:@selector(statusBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
}

-(void)statusBtnAction:(id)sender{
    switch (((UIButton *)sender).tag) {
        case 91:{
            [self.navigationController popViewControllerAnimated:YES];
            self.navigationController.navigationBarHidden = YES;
            self.tabBarController.tabBar.hidden = NO;
        }
            break;
        case 92:{
            TCLYBillViewController * billViewCtr = [[TCLYBillViewController alloc] init];
            [self.navigationController pushViewController:billViewCtr animated:YES];
        }
            break;
    }
}

-(void)topUpBtnAction{
    
    TCLYTopUpViewController * topUpViewCtr = [[TCLYTopUpViewController alloc] init];
    [self.navigationController pushViewController:topUpViewCtr animated:YES];
    
}

-(void)withdrawalBtnAction{
    TCLYWithdrawalViewController * withdrawalViewCtr = [[TCLYWithdrawalViewController alloc] init];
    withdrawalViewCtr.moneyStr = self.moneyStr;
    [self.navigationController pushViewController:withdrawalViewCtr animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
